package test4_16.demo03;

import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.SocketException;

public class UDPServerDoubleTest {
    public static void main(String[] args) {

        try {
            //创建端口
            DatagramSocket ds = new DatagramSocket(1234);
            System.out.println("服务器已启用");
            //创建一个字符缓存数组
            byte[] bytes = new byte[1024];
            //将数据放到数据包里
            DatagramPacket dp = new DatagramPacket(bytes, bytes.length);

            while (true) {
                ds.receive(dp);
                System.out.println("接受的数据：" + new String(bytes, 0, dp.getLength()));
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
